/**
 * 单选
 * @params propItem
 * @returns object
 */

export default {
  props: {
    propItem: Object,
  },
  data() {
    return {
      innerValue: '',
      ...this.propItem,
    };
  },
  mounted() {
    this.innerValue = this.value;
  },
  watch: {
    'propItem.value': {
      // 身份证号回显
      handler(newValue) {
        this.innerValue = newValue;
      },
      deep: true,
    },
  },
  methods: {
    transmit(value) {
      this.$emit('accept', { value, code: this.code });
    },
  },
  render() {
    return (
      <van-field label={this.label} rules={this.rules}>
        <van-radio-group v-model={this.innerValue} direction="horizontal" onChange={this.transmit} slot="input">
          {this.columns.map((item) => (
            <van-radio
              name={item.code}
              scopedSlots={{
                icon: (props) => {
                  return <i class={['primary--text', props.checked ? 'icon-radio-checked' : 'icon-circle']} />;
                },
              }}
            >
              {item.label}
            </van-radio>
          ))}
        </van-radio-group>
      </van-field>
    );
  },
};
